package com.personal.book.service.impl;

import java.util.List;

import com.personal.book.dao.BookDao;
import com.personal.book.dao.impl.BookDaoImpl;
import com.personal.book.entity.Book;
import com.personal.book.service.BookService;
import com.personal.tools.PageData;
import com.sun.org.apache.regexp.internal.recompile;

public class BookServiceImpl implements BookService {
	BookDao dao = new BookDaoImpl();
    /**
     * 分页 通过图书名称模糊查询获取图书信息
     */
	@Override
	public PageData<Book> getInfoByPage(int page, int pageSize, String key) {
		// TODO Auto-generated method stub
		if (page < 1) {
			page = 1;
		}
		return dao.getInfoByPage(page, pageSize, key);
	}
    /**
     * 分页 通过类型获取图书信息
     */
	@Override
	public PageData<Book> getInfoByTypeId(int page, int pageSize,String typeName) {
		// TODO Auto-generated method stub
		if (page < 1) {
			page = 1;
		}
		return dao.getInfoByTypeId(page, pageSize, typeName);
	}
    /**
     *分页  通过价格区间来获取图书信息
     */
	@Override
	public PageData<Book> getInfoByPrice(int page, int pageSize, double max, double min) {
		// TODO Auto-generated method stub
		if (page < 1) {
			page = 1;
		}
		return dao.getInfoByPrice(page, pageSize, max, min);
	}
    /**
     * 分页 通过价格降序排列
     */
	@Override
	public PageData<Book> getInfoOrderByDesc(int page, int pageSize) {
		// TODO Auto-generated method stub
		if (page < 1) {
			page = 1;
		}
		return dao.getInfoOrderByDesc(page, pageSize);
	}
    /**
     * 分页 通过价格升序排列
     */
	@Override
	public PageData<Book> getInfoOrderByAsc(int page, int pageSize) {
		// TODO Auto-generated method stub
		if (page < 1) {
			page = 1;
		}
		return dao.getInfoOrderByAsc(page, pageSize);
	}
    /**
     * 通过图书名称的模糊查询获取信息
     */
	@Override
	public List<Book> getInfoByKey(String key) {
		// TODO Auto-generated method stub
		return dao.getInfoByKey(key);
	}
    /**
     * 通过图书名称查看信息
     */
	@Override
	public Book getInfoByName(String bookName) {
		// TODO Auto-generated method stub
		return dao.getInfoByName(bookName);
	}
    /**
     * 通过图书id获取图书信息
     */
	@Override
	public Book getInfoById(int bookId) {
		// TODO Auto-generated method stub
		return dao.getInfoById(bookId);
	}
    /**
     * 添加图书信息
     * 图书名称不可重复
     */
	@Override
	public boolean addBookInfo(Book book) {
		// TODO Auto-generated method stub
		if (book == null) {
			return false;
		}
		if (dao.getInfoByName(book.getBookName()) != null) {
			return false;
		}
		return dao.addBookInfo(book);
	}
    /**
     * 修改图书信息
     */
	@Override
	public boolean updateBookInfo(Book book) {
		// TODO Auto-generated method stub
		if (book == null) {
			return false;
		}
		return dao.updateBookInfo(book);
	}
    /**
     * 若用户购买商品则修改图书库存
     * 判断参数是否比总库存大
     */
	@Override
	public boolean updateBookCount(int bookId, int count) {
		// TODO Auto-generated method stub
		if ((dao.getInfoById(bookId)).getCount()<=count) {
			return false;
		}
		return dao.updateBookCount(bookId, count);
	}
    /**
     * 查询是否有此id
     * 若有进行删除图书信息
     */
	@Override
	public boolean delBookInfo(int bookId) {
		// TODO Auto-generated method stub
		if (dao.getInfoById(bookId)==null) {
			return false;
		}
		return dao.delBookInfo(bookId);
	}

}
